package com.yz.crm.weixin.service.impl;

import com.yz.common.exception.ServiceException;
import com.yz.crm.weixin.mapper.ThirdPartyUserMapper;
import com.yz.crm.weixin.model.ThirdPartyUser;
import com.yz.crm.weixin.service.ThirdPartyUserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ThirdPartyUserServiceImpl implements ThirdPartyUserService {
    private static final Log log = LogFactory.getLog(ThirdPartyUserServiceImpl.class);
    @Resource
    private SqlSession sqlSession;

    private ThirdPartyUserMapper getMapper() {
        return this.sqlSession.getMapper(ThirdPartyUserMapper.class);
    }


    @Override
    public ThirdPartyUser getInfo(Integer sysUserId, String openId) {
        ThirdPartyUserMapper mapper = this.getMapper();
        ThirdPartyUser thirdPartyUser = new ThirdPartyUser();
        thirdPartyUser.setOpenId(openId);
        return mapper.selectByPrimary(thirdPartyUser);
    }

    @Override
    public ThirdPartyUser getUnionUserInfo(String unionId, String openId, Integer subType) {
        return null;
    }

    @Override
    public int add(ThirdPartyUser thirdParthUser) throws ServiceException {
        ThirdPartyUserMapper mapper = this.getMapper();

        return mapper.insert(thirdParthUser);
    }

    @Override
    public int update(ThirdPartyUser thirdpartyUser) {
        ThirdPartyUserMapper mapper = this.getMapper();

        return mapper.updateByPrimaryKey(thirdpartyUser);
    }

    @Override
    public int updateById(ThirdPartyUser ThirdParthUser) {
        return 0;
    }

    @Override
    public int updateByUnionId(ThirdPartyUser ThirdParthUser) {
        return 0;
    }

    @Override
    public int updateBySysUserId(ThirdPartyUser ThirdParthUser) {
        return 0;
    }

    @Override
    public int updateToUnBind(ThirdPartyUser o) {
        return this.getMapper().updateToUnBind(o);
    }

    @Override
    public int updateToUnBind(Integer sysUserId, String authCode) {
        return 0;
    }
}
